<html>
<meta charset="utf-8">
<body>
<script>
function covert()
{
	var source=WenBen.value;
	var res="";
	var array=[]
	var str="";
	var k=1;
	for(i=source.length;i>0;i--)
	{
		if(source[i-1]!=='\n')
		{
		
		str+=source[i-1];
		k++;
		}
		console.log(source.length-i+1)
		if((source.length-i+1)===source.length%ZheHangZiShu.value)
		{
			var  tmp="";
			for(var j=0;j<ZheHangZiShu.value-(source.length%ZheHangZiShu.value);j++)
			{
			tmp+="　";
			}
			str=tmp+str;
			array.push(str);
			str="";
			k=0;
		}
		if(k%ZheHangZiShu.value===0)
		{
			array.push(str);
			str="";
			k=0;
		}
		
	}
				array.push(str);
			str="";
	console.log(array)
	for(var i=array.length-1;i>=0;i--)
	{
		if(array[i]!="")
		res+=array[i]+"\n";
	}
	return res;
}
</script>
<h1>本工具用于模拟从右到左的文字排版顺序</h1>
<p><span>折行字数</span><textarea id="ZheHangZiShu">11</textarea></p>
<p>
<span>文本</span>
<textarea id="WenBen">
测试
</textarea>
<button onclick="JieGuo.value=covert()">转换</button>
<textarea id="JieGuo">
结果
</textarea>
</p>
</body>
</html>
